<?php
namespace app\common\controller;
use think\Db;
use think\Controller;
use think\Request;
class HomeCommon extends  Controller{
	
	protected $user_id;//用户id
    public function __construct(){
    	
    	header('Access-Control-Allow-Origin:*');
    	
    }
    protected function getusers_by_mobile($mobile){
    	if(empty($mobile)){
    		return ['errcode'=>'10001','msg'=>'手机号不能为空','data'=>[]];
    	}
    	
    	$info=db('users')->field('*')->where(['mobile'=>$mobile])->find();
    	if($info){
    		$info['token']=lock_url($info['id']);
    		unset($info['id']);
    	}
    		
    	return ['errcode'=>'0','msg'=>'返回成功','data'=>$info];
    }
    protected function check_token($token){
    	if(empty($token)){
    		return ['errcode'=>'10001','msg'=>'token不能为空','data'=>[]];
    	}
    	$user_id=unlock_url($token);
    	if(!preg_match( "/^\d*$/",$user_id)){
    		return ['errcode'=>'10002','msg'=>'token错误','data'=>$user_id];
    	}
    	$info=db('users')->field('id')->find($user_id);
    	if(!$info){
    		return ['errcode'=>'10003','msg'=>'token不存在','data'=>[]];
    	}
    	$this->user_id=$user_id;
    	
    	return ['errcode'=>'0','msg'=>'token错误','data'=>['user_id'=>$user_id]];
    }
}
